package cn.funeralobjects.youtube.dl.extension.controller;

import cn.funeralobjects.youtube.dl.extension.controller.model.WatchInfoVo;
import cn.funeralobjects.youtube.dl.extension.converter.WatchInfoConverter;
import cn.funeralobjects.youtube.dl.extension.exec.YoutubeDl;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author FuneralObjects
 * Create date: 2020/4/3 2:42 PM
 */
@RestController
@RequestMapping("/info")
public class InfoController {

    @Resource
    private WatchInfoConverter watchInfoConverter;

    @GetMapping("/{id}")
    public WatchInfoVo getInfo(@PathVariable String id,
                               @RequestParam(value = "proxy",required = false) String proxy){
        if(StringUtils.isEmpty(proxy)){
            return watchInfoConverter.toVo(YoutubeDl.getInfo(id));
        }
        return watchInfoConverter.toVo(YoutubeDl.getInfo(id, proxy));
    }
}
